package ru.pashkan.orga;

import org.springframework.stereotype.Component;

import ru.pashkan.entity.Site;
import ru.pashkan.db.dao.SitesDao;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import ru.pashkan.perspectives.SitesListViewer;

@Component
public class Organizer  implements BasicOrganizer  {
    private String s;

    public void init(String s) {
        this.s = s;
        this.start();
    }

    public void start() {
        System.out.println("say " + s);

        Site site = new Site();
        site.setSiteName("Test1");

        ApplicationContext appContext = new ClassPathXmlApplicationContext(new String[]{"applicationContext-db.xml"});
        SitesDao siteDao = (SitesDao) appContext.getBean("SitesDao");
//        siteDao.saveSite(site);
        int i = 0;
		while(i < siteDao.takeSite().size()){

			System.out.println(siteDao.takeSite().get(i).getSiteName() + " - " + siteDao.takeSite().get(i).getSiteUrl());
            i++;
		}

        SitesListViewer SitesListViewer = new SitesListViewer();
        SitesListViewer.runShell();
    }
}
